(function () {
  const switch_mode = document.querySelector(".switch_mode");
  const removeClass = "dark";
  function insertLink() {
    const head = document.querySelector("head");
    const link = document.createElement("link");
    link.className = removeClass;
    link.rel = "stylesheet";
    link.href = "/dist/code-atom-dark.css";
    head.appendChild(link);
    // switch_mode.dataset.label = "dark";
  }

  function removeLink() {
    const link = document.querySelector(`.${removeClass}`);
    if (link) {
      link.remove();
      // switch_mode.dataset.label = "light";
    }
  }

  switch_mode.addEventListener("change", function (e) {
    if (e.target.checked) {
      insertLink();
    } else {
      removeLink();
    }
  });
})();
